package com.neusoft.yuejian_6.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.javabean.Video;

import java.util.List;

import static com.neusoft.yuejian_6.base.Constant.PHOTO_URL;

/**
 * Created by Q on 2017/10/27.
 */

public class VideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;
    private VideoView videoView;
    // private MediaController mediaController;
    private Button mbutton;


    public VideoAdapter(Context mContext, List mDataList) {
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext())
                .inflate(R.layout.cardview_video, parent, false);
        return new ViewHolder(v);

    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        VideoView videoView;
        TextView video_name;


        public ViewHolder(View itemView) {
            super(itemView);
            videoView = (VideoView) itemView.findViewById(R.id.videoView);
            video_name = (TextView) itemView.findViewById(R.id.video_name);
            videoView.setMediaController(new MediaController(mContex));

        }}@Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final Video entity = (Video) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.video_name.setText(entity.getVideo_title());

        Uri uri = Uri.parse(PHOTO_URL + entity.getVideo_videos());
        viewHolder.videoView.setVideoURI(uri);

        //Log.d("a","videoView");

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }


}
